package com.cr.attach.controller;

import com.cr.attach.service.IAttachService;
import com.cr.common.response.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Api(tags = "附件模块")
@RestController
@RequestMapping("/api/attach")
public class AttachController {

    @Autowired
    private IAttachService attachService;

    @ApiOperation(value = "上传图片")
    @PostMapping("/uploadImage")
    public JsonResult uploadImage(@RequestParam("file") MultipartFile file) {
        String url = attachService.upload(file);
        return JsonResult.success(url);
    }

    @ApiOperation(value = "删除文件")
    @PostMapping("/remove")
    public JsonResult remove(String url) {
        attachService.deleteByUrl(url);
        return JsonResult.success();
    }

}
